﻿
/***更新****************************************************************   
*       最后更新 : ZhangJunhua   
*       更新日期 : 2010/04/15   
*       更新目的 : 增加  功能；修复bug   
*       更新版本 : 1.00   
*       更新日志 : 日志   
************************************************************************/     
  
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace System
{
    /// <summary>
    /// 
    /// </summary>
    public class StringTokenizer
    {
        private string data, delimiter;
        private string[] tokens;
        private int index;

        /// <summary>
        ///  StringTokenizer:构造函数
        /// </summary>
        /// <param name="dataLine"></param>
        public StringTokenizer(string dataLine)
        {
            init(dataLine, " ");
        }

        /// <summary>
        ///  StringTokenizer:重载构造函数
        /// </summary>
        /// <param name="dataLine"></param>
        /// <param name="delim"></param>
        public StringTokenizer(string dataLine, string delim)
        {
            init(dataLine, delim);
        }

        private void init(string dataLine, String delim)
        {
            data = dataLine;
            delimiter = delim;
            //
            // 将字符串转化为数组
            tokens = data.Split(delimiter.ToCharArray());
            index = 0;
        }

        // 判断是否还有单词
        public bool hasMoreTokens()
        {
            return (index < (tokens.Length));
        }

        public string nextToken()
        {
            if (index < tokens.Length)
            {
                return tokens[index++];
            }
            else
                return null;
        }

        public int countTokens()
        {
            return (tokens.Length);
        }
    }
}
